﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace SharePointPowerToys
{
    public class ButtonHeaderSharePointEditorPartControl : Control, INamingContainer
    {
        public string Header { get; set; }
        public string Body { get; set; }

        private HiddenField textHiddenField = new HiddenField();
        public string Text
        {
            get
            {
                return textHiddenField.Value;
            }

            set
            {
                textHiddenField.Value = value;
            }
        }

        public ButtonHeaderSharePointEditorPartControl()
        {
        }

        public ButtonHeaderSharePointEditorPartControl(string header)
        {
            Header = header;
            Body = string.Empty;
        }

        public ButtonHeaderSharePointEditorPartControl(string header, string body)
        {
            Header = header;
            Body = body;
        }

        public ButtonHeaderSharePointEditorPartControl(string header, string body, string text)
        {
            Header = header;
            Body = body;
            Text = text;
        }

        protected override void CreateChildControls()
        {
            Page.ClientScript.RegisterClientScriptInclude("xtp", "/_layouts/1033/xtp.js");

            //Controls.Add(new LiteralControl("<tr>"));
            //Controls.Add(new LiteralControl("<td>"));
            Controls.Add(new LiteralControl("<div class=\"UserSectionHead ms-bold\">"));

            textHiddenField.ID = String.Concat(ID, "textValue");
            textHiddenField.Value = Text;

            Controls.Add(textHiddenField);

            Controls.Add(new LiteralControl(Header));
            Controls.Add(new LiteralControl("</div>"));

            Controls.Add(new LiteralControl("<div class=\"UserSectionBody\">"));

            Controls.Add(new LiteralControl("<div class=\"UserControlGroup\">"));
            Controls.Add(new LiteralControl("<nobr>"));
            //Controls.Add(new TextBox { ID = this.ID + "TextBox", CssClass = "UserInput", Width = 176 });

            Button builderButton = new Button();
            builderButton.ID = this.ID + "BuilderButton";
            Controls.Add(builderButton);

            //id=\"MsoXmlToolpartBasicAddXml\"
            builderButton.Text = String.Concat(Header, "...");
            //builderButton.StyleCssClass = "UserButton";
            //builderButton.Attributes.Add("onclick", String.Concat("javascript:MSOPGrid_doBuilder('\u002f_layouts\u002fzoombldr.aspx?culture=en-US', ", builderButton.ClientID.ToString(), ", 'dialogHeight:340px;dialogWidth:430px;help:no;status:no;resizable:yes');"));
            builderButton.Attributes.Add("onclick", String.Concat("javascript:MsoXmlToolpartSourceEdit('\u002f_layouts\u002fzoombldr.aspx?culture=en-US', ", textHiddenField.ClientID.ToString(), ");return false;"));
            //onclick="javascript:MsoXmlToolpartSourceEdit('\u002f_layouts\u002fzoombldr.aspx?culture=en-US',MsoXmlToolpartBasicXmlProperty)\"
            builderButton.Attributes.Add("class", "UserButton");


            Controls.Add(new LiteralControl("</nobr>"));
            Controls.Add(new LiteralControl("</div>"));
            Controls.Add(new LiteralControl("</div>"));

            //Controls.Add(new LiteralControl("<div class=\"UserDottedLine\" width=\"100%\"/>"));
            //Controls.Add(new LiteralControl("</td>"));
            //Controls.Add(new LiteralControl("</tr>"));
        }
    }
}
